package com.ymatou.iapi.optrade.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.ymatou.iapi.optrade.parameter.enums.CancelOrderTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.parameter.req.ApplyRefundReq;
import com.ymatou.iapi.optrade.parameter.req.CancelOrderReq;
import com.ymatou.iapi.optrade.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.optrade.parameter.utill.Utils;
import com.ymatou.iapi.optrade.parameter.vo.CouponVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderGroupVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderItemVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderVo;
import com.ymatou.iapi.optrade.resp.Order;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.optrade.service.BargainGroupService;
import com.ymatou.iapi.optrade.service.CancelOrderCall;
import com.ymatou.iapi.optrade.service.PrepaidCardService;
import com.ymatou.iapi.optrade.service.RefundService;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.business.service.YMTTrading.TradingAllPromotion;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceAnliOrderCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceEngageOrderCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.business.service.YMTTrading.TradingProductVo;
import com.ymttest.database.model.AccountEntry;
import com.ymttest.database.model.coupon;
import com.ymttest.database.sharding.db.sharding.model.MainOrderPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.OrderStatusLogPo;
import com.ymttest.database.sharding.db.sharding.model.UserRefundFundDetailPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.database.sqlwapper.couponWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 取消订单 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CancelOrder {

	private static CancelOrderReq cancelorderReq;
	private static CancelOrderCall cancelordercall;

	private static long userId = Long.valueOf(EnvSetup.getData("BuyUserId"));

	private static OrderShardingWapper database = new OrderShardingWapper();
	
	private static Long sellerId = Long.valueOf(EnvSetup.getData("autotest_seller1"));
	private static String sellerName = String.valueOf(EnvSetup.getData("autotest_sellerName1"));

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("取消订单");
	}

	@Before
	public void caseUp() {
		cancelorderReq = new CancelOrderReq();
		cancelordercall = new CancelOrderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cancelordercall.getOpurl());
		database.activeDeadCommunicationsLink(database);
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 多买手,多商品,生成多个订单 同时使用平台券，商家券
	 * 
	 * @param isUserCoupon
	 * @return
	 */
	public static TradingServiceResp placeOrder5(boolean isUserCoupon) {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();

		long userId = placeOrderReq.getUserId();
		
		OrderGroupVo orderGroupVo1 = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo1 = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo productVo1 = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		TradingProductVo productVo2 = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo1 = TradingCallService.createOrderItemVo(
				productVo1.getProductId(), productVo1.getCatalogId());
		OrderItemVo orderItemVo2 = TradingCallService.createOrderItemVo(
				productVo2.getProductId(), productVo2.getCatalogId());

		orderVo1.setOrderItems(Arrays.asList(orderItemVo1, orderItemVo2));
		orderGroupVo1.setOrders(Arrays.asList(orderVo1));
		
		// 买手2 订单组
		long sellerId2 = Long.valueOf(EnvSetup.getData("SellerId"));
		String sellerName2 = String.valueOf(EnvSetup.getData("SellerName"));
		
		OrderGroupVo orderGroupVo2 = TradingCallService.createOrderGroupVo(
				sellerId2, sellerName2);
		
		OrderVo orderVo2 = TradingCallService.createOrderVo();

		TradingProductVo productVo3 = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		TradingProductVo productVo4 = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo3 = TradingCallService.createOrderItemVo(
				productVo3.getProductId(), productVo3.getCatalogId());
		OrderItemVo orderItemVo4 = TradingCallService.createOrderItemVo(
				productVo4.getProductId(), productVo4.getCatalogId());

		orderVo2.setOrderItems(Arrays.asList(orderItemVo3, orderItemVo4));
		orderGroupVo2.setOrders(Lists.newArrayList(orderVo2));

		if (isUserCoupon) {

			CouponVo sellerCoupon1 = TradingAllPromotion.createSellerCouponVo(
					userId, sellerId, new BigDecimal(30), BigDecimal.TEN);

			orderGroupVo1.setSellerCoupon(sellerCoupon1);

			orderGroupVo2.setSellerCoupon(TradingAllPromotion.createSellerCouponVo(
					userId, sellerId, new BigDecimal(30), new BigDecimal(15)));
			placeOrderReq.setYmatouCoupon(TradingAllPromotion.createYMTCouponVo(
					userId, new BigDecimal(60), BigDecimal.TEN));
		}

		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo1, orderGroupVo2));

		return TradingCallService.callPlaceOrderService(placeOrderReq);
	}

	/***
	 * 创建预售一个订单
	 * 
	 * @return
	 */
	private TradingServiceResp createPreSaleOrder() {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		orderItemVo.setPreSale(true);
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 根据 couponCode 查询优惠券是否使用
	 * 
	 * @param couponCode
	 * @return true 已使用 ;false 未使用
	 */
	public static boolean isCouponCodeUsed(String couponCode) {

		boolean isUsered = false;

		coupon coupon = new couponWapper().selectBycouponCode(couponCode)
				.get(0);
		isUsered = coupon.getIsUsed();

		return isUsered;
	}

	/**
	 * 校验订单表状态，单主状态操作日志表
	 */
	public static void verifyOrderStatus(int orderStatus, long orderId,
			long userId, CancelOrderTypeEnum type, String cancelReason) {

		// 订单表(order)
		OrderPo ymtOrders = database.selectOrderbyOrderId(orderId);

		Logger.comment(String.format("验证订单表(order)表 orderId: %s", orderId));

		Logger.verifyEquals(orderStatus, ymtOrders.getOrderStatus(),
				"验证orderStatus");

		// 订单主状态操作日志表(order_status_log)
		OrderStatusLogPo orderStatusLogPo = database
				.selectOrderStatusLogByOrderId(orderId);

		Logger.comment("验证订单主状态操作日志表(order_status_log)");

		String cancelMemo = "";

		int orderStatusMemo = 400000;

		switch (type.getCode()) {
		case 1:
			cancelMemo = "买家取消订单";
			orderStatusMemo = 100000;
			break;
		case 2:
			cancelMemo = cancelReason;
			orderStatusMemo = 200000;
			break;
		case 3:
			cancelMemo = cancelReason;
			orderStatusMemo = 300000;
			break;
		case 4:
			cancelMemo = "系统取消订单";
			orderStatusMemo = 400000;
			break;
		case 5:
			cancelMemo = "风控系统自动取消订单";
			orderStatusMemo = 500000;
			break;
		case 7:
			cancelMemo = "收件人额度超过2万金额取消订单";
			orderStatusMemo = 700000;
			break;
		case 8:
			cancelMemo = "全款未支付取消订单";
			orderStatusMemo = 800000;
			break;
		case 9:
			cancelMemo = "买手未发货取消订单";
			orderStatusMemo = 900000;
			break;
		default:
			cancelMemo = cancelReason;
			break;
		}

		Logger.verifyEquals(orderStatusMemo, ymtOrders.getOrderStatusMemo(),
				"验证orderStatusMemo");

		Logger.verifyEquals(cancelMemo, orderStatusLogPo.getMemo(), "验证数据库Memo");
		Logger.verifyEquals(orderStatus, orderStatusLogPo.getOrderStatus(),
				"验证数据库OrderStatus");

		Logger.verifyEquals(true,
				Utils.calcTimeSpanMin(orderStatusLogPo.getAddTime()) < 2,
				"验证数据库AddTime跟系统当前时间差为2分钟内");

		Logger.verifyEquals(orderId, orderStatusLogPo.getOrderId(),
				"验证数据库OrderId");
		Logger.verifyEquals(userId, orderStatusLogPo.getOperator(),
				"验证数据库Operator");
	}

	/**
	 * 用户退款资金详情表（user_refund_fund_detail）
	 * 
	 * @param expected
	 * @param actual
	 */
	public static void verifyUserRefundFundDetailDb(
			UserRefundFundDetailPo expected, UserRefundFundDetailPo actual) {

		Logger.comment(String
				.format("验证退用户退款资金详情表（user_refund_fund_detail） OrderId :%s payment_id :%s",
						expected.getOrderId(), expected.getPaymentId()));

		Logger.verifyEquals(true,
				Utils.calcTimeSpanMin(actual.getUpdateTime()) < 2,
				"验证数据库UpdateTime跟系统当前时间差为2分钟内");
		Logger.verifyEquals(true,
				Utils.calcTimeSpanMin(actual.getAddTime()) < 2,
				"验证数据库AddTime跟系统当前时间差为2分钟内");

		Logger.verifyEquals(expected.getBizType(), actual.getBizType(),
				"验证数据库BizType");
		Logger.verifyEquals(expected.getPaymentId(), actual.getPaymentId(),
				"验证数据库PaymentId");

		DataUtil.verifyDecimalEquals(expected.getThirdpartyDiscount(),
				actual.getThirdpartyDiscount(), "验证数据库ThirdpartyDiscount");
		Logger.verifyEquals(expected.getMemo(), actual.getMemo() == null ? "0"
				: actual.getMemo(), "验证数据库Memo");
		DataUtil.verifyDecimalEquals(expected.getThirdpartyAmount(),
				actual.getThirdpartyAmount(), "验证数据库ThirdpartyAmount");
		Logger.verifyEquals(expected.getAccountRefundStatus(),
				actual.getAccountRefundStatus(), "验证数据库AccountRefundStatus");
		Logger.verifyEquals(expected.getThirdpartyRefundStatus(),
				actual.getThirdpartyRefundStatus(),
				"验证数据库ThirdpartyRefundStatus");
		/*
		 * Logger.verifyEquals(expected.getAccountRefundTime(),
		 * actual.getAccountRefundTime(), "验证数据库AccountRefundTime");
		 */

		Logger.verifyEquals(true,
				Utils.calcTimeSpanMin(actual.getThirdpartyRefundTime()) < 2,
				"验证数据库ThirdpartyRefundTime跟系统当前时间差为2分钟内");

		Logger.verifyEquals(expected.getRetryTimes(), actual.getRetryTimes(),
				"验证数据库RetryTimes");

		DataUtil.verifyDecimalEquals(expected.getAccountAmount(),
				actual.getAccountAmount(), "验证数据库AccountAmount");

	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_047() {
		Logger.start(true, "使用了预付卡订单,余额+第三方支付后，取消订单");
		try {
			Logger.comment("准备前置数据");

			TradingServiceResp placeOrderResp = PrepaidCardService
					.placeOrder2(false);

			List<Order> orders = placeOrderResp.getOrderList();

			Long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();

			long orderId = orders.get(0).getOrderId();

			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 用余额支付
			BigDecimal useAccountAmount = new BigDecimal(10);

			// 买家付款

			Long thirdTradingId = TradingCallService.payOrder(userId,
					useAccountAmount, tradingId, "13");

			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall("13",
					String.valueOf(thirdTradingId),
					totalPrice.subtract(useAccountAmount).toString(),
					userId.intValue());

			Thread.sleep(5000);

			Logger.comment("准备前置数据结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			Thread.sleep(2000);
			
			database.clearCache();

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason()); // 数据库验证

			// 订单表(order)
			OrderPo ymtOrders = database.selectOrderbyOrderId(orderId);

			UserRefundFundDetailPo userRefundFundDetailPo = database
					.selectUserRefundFundDetailByBizno(String.valueOf(orderId));

			DataUtil.verifyDateEquals(
					ymtOrders.getCardAmount(),
					PrepaidCardService.getCardEntry(userId.intValue(),
							String.valueOf(orderId)), "校验取消订单退回的预付卡金额");

			BigDecimal refundAmount = userRefundFundDetailPo.getAccountAmount()
					.add(userRefundFundDetailPo.getThirdpartyAmount());

			DataUtil.verifyDateEquals(ymtOrders.getPayableAmount(),
					refundAmount, "校验取消订单资金原路退回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_001() {
		Logger.start(true, "订单支付前,买家取消订单成功,订单状态为12 买家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithCoupon();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证

			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_002() {
		Logger.start(true, "订单支付前,卖家取消订单成功,订单状态为13 卖家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithSixProcutAndFourOrdersInTwoSeller(true,
							BigDecimal.ZERO, 20325087);

			for (Order order : placeOrderResp.getOrderList()) {

				long orderId = order.getOrderId();

				long sellerId = order.getSellerId();

				String cancelReason = "自动化测试取消订单";
				cancelorderReq.setCancelReason(cancelReason);
				cancelorderReq
						.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
				cancelorderReq.setOrderId(orderId);
				// 卖家取消的时候，为卖家ID
				cancelorderReq.setUserId(sellerId);
				// 发送请求
				cancelordercall.setData(cancelorderReq);
				cancelordercall.callService();
				Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
						"验证Code");

				// 数据库验证
				verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
						cancelorderReq.getCancelType(),
						cancelorderReq.getCancelReason());

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_003() {
		Logger.start(true, "订单支付前, 系统自动取消订单,订单状态为18 系统取消");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithCoupon();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();
			
			TradingSyncService.getSyncResult(orderId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SYSTEM_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_003_1() {
		Logger.start(true, "订单支付前, 系统自动取消订单,订单状态为18 系统自动取消");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithCoupon();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			// 修改下单时间
			OrderPo record = database.selectOrderbyOrderId(orderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR, -1);

			record.setAddTime(calendar.getTime());

			database.orderMapper.updateByPrimaryKey(record);

			String orderJson = "{\"cancelReason\":\"自动化测试取消订单\",\"cancelType\":\"4\",\"orderId\":"
					+ orderId + ",\"userId\":" + userId + "}";

			// 发送请求
			YmatouEasyCall autoCancelOrderCall = new YmatouEasyCall("", "POST",
					"JSON");
			autoCancelOrderCall
					.setUrl("http://optrade.iapi.ymatou.com/api/Buyer/AutoCancelOrder");
			autoCancelOrderCall.setData(orderJson);
			autoCancelOrderCall.callService();

			Logger.verifyEquals("ok", autoCancelOrderCall.getReturnData(),
					"验证ReturnData");

			// 数据库验证
			OrderPo actualOrder = database
					.selectOrderbyOrderId(orderId);

			Logger.verifyEquals(18, actualOrder.getOrderStatus(),
					"验证orderStatus");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_004() {
		Logger.start(true, "订单支付前,客服取消订单成功,订单状态为18 系统取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithCoupon();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_005() {
		Logger.start(true, "订单支付后,风控取消订单成功，订单状态为18 系统自动取消");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService.payOrder();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试风控取消订单";

			Thread.sleep(3000);

			OrderPo record = new OrderPo();

			record.setOrderId(orderId);
			record.setRiskStatus(0);

			// 修改订单风控状态为0
			database.orderMapper.updateByPrimaryKeySelective(record);

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.RISKCONTROL_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(-1L); // 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_006() {
		Logger.start(true, "订单已支付商家未接单,买家取消订单成功，订单状态为12 买家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			// 下单
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithSixProcutAndFourOrdersInTwoSeller(true,
							BigDecimal.ZERO, userId);
			// 支付订单
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());

			for (Order order : placeOrderResp.getOrderList()) {

				long orderId = order.getOrderId();

				long userId = placeOrderResp.getUserId();

				Logger.comment("前置数据准备结束");
				String cancelReason = "自动化测试取消订单";
				cancelorderReq.setCancelReason(cancelReason);
				cancelorderReq
						.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
				cancelorderReq.setOrderId(orderId);
				cancelorderReq.setUserId(userId);
				// 发送请求
				cancelordercall.setData(cancelorderReq);
				cancelordercall.callService();
				Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
						"验证Code");
				// 数据库验证
				verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
						cancelorderReq.getCancelType(),
						cancelorderReq.getCancelReason());

			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_007() {
		Logger.start(true, "订单已支付商家未接单,卖家取消订单成功，订单状态为13 卖家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			// 下单
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService.placeOrderWithThreeProcutInTwoOrder(
					true, BigDecimal.ZERO, userId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY);
			// 支付订单
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());

			for (Order order : placeOrderResp.getOrderList()) {

				long orderId = order.getOrderId();

				long sellerId = order.getSellerId();

				Logger.comment("前置数据准备结束");
				String cancelReason = "自动化测试取消订单";
				cancelorderReq.setCancelReason(cancelReason);
				cancelorderReq
						.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
				cancelorderReq.setOrderId(orderId);
				cancelorderReq.setUserId(sellerId);
				// 发送请求
				cancelordercall.setData(cancelorderReq);
				cancelordercall.callService();
				Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
						"验证Code");
				// 数据库验证
				verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
						cancelorderReq.getCancelType(),
						cancelorderReq.getCancelReason());

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_008() {
		Logger.start(true, "订单已支付商家未接单,客服取消订单成功，订单状态为18 卖家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService.payOrder();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(-1L);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_009() {
		Logger.start(true, "订单在退货退款中,取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderApplyRefund();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(String.format("哈尼，此单%s有退货/退款，请先去处理~", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_010() {
		Logger.start(true, "订单卖家已接单,客服取消订单成功，订单状态为18 系统取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试客服取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			cancelorderReq.setUserId(-1L);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_011() {
		Logger.start(true, "商家已接单,买家取消订单失败");
		try {

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试客服取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("102", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(String.format("买家取消订单%s状态不匹配", orderId),
					cancelordercall.getMsg(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_012() {
		Logger.start(true, "商家已接单,商家取消订单失败");
		try {

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试客服取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);

			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(
					String.format("哈尼，接单后不能再取消订单了哦，请让买家申请退货退款~", orderId),
					cancelordercall.getMsg(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_013() {
		Logger.start(true, "订单已收货,,客服取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderConfirmReceive();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("客服取消订单" + orderId + "状态不匹配",
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_014() {
		Logger.start(true, "订单已支付商家未接单,使用平台,商家优惠券风控取消订单成功,不退优惠券");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithCoupon();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");

			Thread.sleep(3000);

			OrderPo record = new OrderPo();

			record.setOrderId(orderId);
			record.setRiskStatus(0);

			database.orderExample.createCriteria().andOrderIdEqualTo(orderId);
			// 修改订单风控状态为0
			database.orderMapper.updateByExampleSelective(record,
					database.orderExample);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试风控取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.RISKCONTROL_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(-1L); // 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Thread.sleep(2000);

			Logger.verifyEquals(true,
					isCouponCodeUsed(order.getYmtCouponCode()), "验证ymt平台优惠券不退回");

			Logger.verifyEquals(true,
					isCouponCodeUsed(order.getSellerCouponCode()), "验证商家优惠券不退回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_015() {
		Logger.start(true, "接单前取消,退优惠券");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithCoupon();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId); // 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Thread.sleep(5000);

			Logger.verifyEquals(false,
					isCouponCodeUsed(order.getYmtCouponCode()), "验证ymt平台优惠券退回");

			Logger.verifyEquals(false,
					isCouponCodeUsed(order.getSellerCouponCode()), "验证商家优惠券退回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_016() {
		Logger.start(true, "使用平台,商家优惠券.接单后客服取消订单,不退优惠券");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithCoupon();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			long sellerId = order.getSellerId();

			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");

			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(-1L);
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Thread.sleep(2000);

			Logger.verifyEquals(true,
					isCouponCodeUsed(order.getYmtCouponCode()), "验证ymt平台优惠券不退回");

			Logger.verifyEquals(true,
					isCouponCodeUsed(order.getSellerCouponCode()), "验证商家优惠券不退回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_017() {
		Logger.start(true, "未付款状态,同一主单号下面订单全部取消,平台优惠券,商家券全部退回");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = placeOrder5(true);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			for (int i = 1; i < placeOrderResp.getOrderList().size(); i++) {

				long id = placeOrderResp.getOrderList().get(i).getOrderId();

				TradingCallService.cancelOrder(id,
						CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
			}

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Thread.sleep(5000);

			Logger.verifyEquals(false,
					isCouponCodeUsed(order.getYmtCouponCode()), "验证ymt平台优惠券退回");

			List<String> sellerCouponList = new ArrayList<String>();

			for (Order o : placeOrderResp.getOrderList()) {

				String sellerCoupon = o.getOrderPo().getSellerCouponCode();

				if (!sellerCouponList.contains(sellerCoupon)) {

					sellerCouponList.add(sellerCoupon);

				}

			}

			for (String code : sellerCouponList) {
				Logger.verifyEquals(false,
						isCouponCodeUsed(order.getSellerCouponCode()),
						String.format("验证商家优惠券: %s 退回", code));
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_018() {
		Logger.start(true, "已付款状态:同一主单号下面只有1个商家的订单,订单全部取消才退回平台优惠券");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true, BigDecimal.ZERO,
							userId, LogisticsTypeEnum.OVERSEAS_DELIVERY);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");

			for (int i = 1; i < placeOrderResp.getOrderList().size(); i++) {

				long id = placeOrderResp.getOrderList().get(i).getOrderId();

				TradingCallService.cancelOrder(id,
						CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
			}

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Thread.sleep(5000);

			Logger.verifyEquals(false,
					isCouponCodeUsed(order.getYmtCouponCode()), "验证ymt平台优惠券退回");

			Logger.verifyEquals(false,
					isCouponCodeUsed(order.getSellerCouponCode()), "验证商家优惠券退回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_019() {
		Logger.start(true, "已付款状态:同一主单号下面有多个商家的订单,即使订单全部取消,退回商家券,不退回平台优惠券");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = placeOrder5(true);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");

			for (int i = 1; i < placeOrderResp.getOrderList().size(); i++) {

				long id = placeOrderResp.getOrderList().get(i).getOrderId();

				TradingCallService.cancelOrder(id,
						CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
			}

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Thread.sleep(2000);

			Logger.verifyEquals(true,
					isCouponCodeUsed(order.getYmtCouponCode()), "验证ymt平台优惠券不退回");

			List<String> sellerCouponList = new ArrayList<String>();

			for (Order o : placeOrderResp.getOrderList()) {

				String sellerCoupon = o.getOrderPo().getSellerCouponCode();

				if (!sellerCouponList.contains(sellerCoupon)) {

					sellerCouponList.add(sellerCoupon);
				}

			}

			for (String code : sellerCouponList) {
				Logger.verifyEquals(false,
						isCouponCodeUsed(order.getSellerCouponCode()),
						String.format("验证商家优惠券: %s 退回", code));
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_020() {
		Logger.start(true, "订单用余额全款付款后,取消订单,校验资金退账户余额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService.payOrder();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Map m = new HashMap();

			m.put("userId", userId);
			m.put("bizno", orderId);
			m.put("originalNo", orderId);

			AccountEntry res = new AccountWapper().selectAccountEntryByBizNo(m)
					.get(0);

			DataUtil.verifyDecimalEquals(placeOrderResp.getPayableAmount(),
					res.getAmount(), "校验取消订单退款入账流水金额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_021() {
		Logger.start(true,
				"订单用余额+支付宝组合支付,卖家接单前取消订单,校验使用余额支付退余额,使用第三方支付宝,原路退回到支付宝");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLuxury(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			BigDecimal useAccountAmount = new BigDecimal(10);

			Long thirdTradingId = TradingCallService.payOrder(userId,
					useAccountAmount, placeOrderResp.getMainOrderId(), "13");

			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(useAccountAmount).toString(),
					userId.intValue());

			Thread.sleep(4000);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			Thread.sleep(2000);

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());
			Map m = new HashMap();

			m.put("userId", userId);
			m.put("bizno", orderId);
			m.put("originalNo", orderId);

			AccountEntry res = new AccountWapper().selectAccountEntryByBizNo(m)
					.get(0);

			DataUtil.verifyDecimalEquals(useAccountAmount, res.getAmount(),
					"校验取消订单退款入账流水金额");

			// 用户退款资金详情表（user_refund_fund_detail）
			UserRefundFundDetailPo userRefundFundDetailPo = database
					.selectUserRefundFundDetailByPaymentId(Long
							.valueOf(thirdTradingId));

			UserRefundFundDetailPo expectUserRefundFundDetailPo = new UserRefundFundDetailPo();

			expectUserRefundFundDetailPo.setPaymentId(Long
					.valueOf(thirdTradingId));
			expectUserRefundFundDetailPo.setAccountRefundStatus(4);
			expectUserRefundFundDetailPo.setBizType(2);
			expectUserRefundFundDetailPo.setThirdpartyAmount(totalPrice
					.subtract(useAccountAmount));
			expectUserRefundFundDetailPo.setThirdpartyRefundStatus(3);
			expectUserRefundFundDetailPo.setRetryTimes(0);
			expectUserRefundFundDetailPo.setMemo("0");
			expectUserRefundFundDetailPo.setAccountAmount(useAccountAmount);

			verifyUserRefundFundDetailDb(expectUserRefundFundDetailPo,
					userRefundFundDetailPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_022() {
		Logger.start(true, "订单用余额+微信组合支付,卖家接单前取消订单,校验使用第三方微信，原路退回微信");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLuxury(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			BigDecimal useAccountAmount = new BigDecimal(10);

			Long thirdTradingId = TradingCallService.payOrder(userId,
					useAccountAmount, placeOrderResp.getMainOrderId(), "15");

			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall("15", thirdTradingId.toString(),
					totalPrice.subtract(useAccountAmount).toString(),
					userId.intValue());

			Thread.sleep(4000);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			Thread.sleep(2000);

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Map m = new HashMap();

			m.put("userId", userId);
			m.put("bizno", orderId);
			m.put("originalNo", orderId);

			AccountEntry res = new AccountWapper().selectAccountEntryByBizNo(m)
					.get(0);

			DataUtil.verifyDecimalEquals(useAccountAmount, res.getAmount(),
					"校验取消订单退款入账流水金额");

			// 用户退款资金详情表（user_refund_fund_detail）
			UserRefundFundDetailPo userRefundFundDetailPo = database
					.selectUserRefundFundDetailByPaymentId(Long
							.valueOf(thirdTradingId));

			UserRefundFundDetailPo expectUserRefundFundDetailPo = new UserRefundFundDetailPo();

			expectUserRefundFundDetailPo.setPaymentId(Long
					.valueOf(thirdTradingId));
			expectUserRefundFundDetailPo.setAccountRefundStatus(4);
			expectUserRefundFundDetailPo.setBizType(2);
			expectUserRefundFundDetailPo.setThirdpartyAmount(totalPrice
					.subtract(useAccountAmount));
			expectUserRefundFundDetailPo.setThirdpartyRefundStatus(3);
			expectUserRefundFundDetailPo.setRetryTimes(0);
			expectUserRefundFundDetailPo.setMemo("0");
			expectUserRefundFundDetailPo.setAccountAmount(useAccountAmount);

			verifyUserRefundFundDetailDb(expectUserRefundFundDetailPo,
					userRefundFundDetailPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_023() {
		Logger.start(true, "订单用支付宝全款支付,卖家接单前取消订单,校验原路退回到支付宝");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLuxury(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			BigDecimal useAccountAmount = BigDecimal.ZERO;

			Long thirdTradingId = TradingCallService.payOrder(userId,
					useAccountAmount, placeOrderResp.getMainOrderId(), "13");

			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(useAccountAmount).toString(),
					userId.intValue());

			Thread.sleep(4000);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			Thread.sleep(2000);

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			// 用户退款资金详情表（user_refund_fund_detail）
			UserRefundFundDetailPo userRefundFundDetailPo = database
					.selectUserRefundFundDetailByPaymentId(Long
							.valueOf(thirdTradingId));

			UserRefundFundDetailPo expectUserRefundFundDetailPo = new UserRefundFundDetailPo();

			expectUserRefundFundDetailPo.setPaymentId(Long
					.valueOf(thirdTradingId));
			expectUserRefundFundDetailPo.setAccountRefundStatus(-1);
			expectUserRefundFundDetailPo.setBizType(2);
			expectUserRefundFundDetailPo.setThirdpartyAmount(totalPrice
					.subtract(useAccountAmount));
			expectUserRefundFundDetailPo.setThirdpartyRefundStatus(3);
			expectUserRefundFundDetailPo.setRetryTimes(0);
			expectUserRefundFundDetailPo.setMemo("0");
			expectUserRefundFundDetailPo.setAccountAmount(useAccountAmount);

			verifyUserRefundFundDetailDb(expectUserRefundFundDetailPo,
					userRefundFundDetailPo);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_024() {
		Logger.start(true, "订单用微信全款支付,卖家接单前取消订单,校验原路退回微信");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLuxury(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			BigDecimal useAccountAmount = BigDecimal.ZERO;

			Long thirdTradingId = TradingCallService.payOrder(userId,
					useAccountAmount, placeOrderResp.getMainOrderId(), "15");

			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall("15", thirdTradingId.toString(),
					totalPrice.subtract(useAccountAmount).toString(),
					userId.intValue());

			Thread.sleep(6000);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Thread.sleep(6000);
			
			// 用户退款资金详情表（user_refund_fund_detail）
			UserRefundFundDetailPo userRefundFundDetailPo = database
					.selectUserRefundFundDetailByPaymentId(Long
							.valueOf(thirdTradingId));

			UserRefundFundDetailPo expectUserRefundFundDetailPo = new UserRefundFundDetailPo();

			expectUserRefundFundDetailPo.setOrderId(orderId);
			expectUserRefundFundDetailPo.setPaymentId(Long
					.valueOf(thirdTradingId));
			expectUserRefundFundDetailPo.setAccountRefundStatus(-1);
			expectUserRefundFundDetailPo.setBizType(2);
			expectUserRefundFundDetailPo.setThirdpartyAmount(totalPrice
					.subtract(useAccountAmount));
			expectUserRefundFundDetailPo.setThirdpartyRefundStatus(3);
			expectUserRefundFundDetailPo.setRetryTimes(0);
			expectUserRefundFundDetailPo.setMemo("0");
			expectUserRefundFundDetailPo.setAccountAmount(useAccountAmount);

			Thread.sleep(3000);

			verifyUserRefundFundDetailDb(expectUserRefundFundDetailPo,
					userRefundFundDetailPo);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_025() {
		Logger.start(true, "一笔交易生成多个订单,(用户余额+第三方组合支付),取消其中一单。校验退款余额和第三方支付的原路返回");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = placeOrder5(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			BigDecimal useAccountAmount = new BigDecimal(10);

			Long thirdTradingId = TradingCallService.payOrder(userId,
					useAccountAmount, placeOrderResp.getMainOrderId(), "15");

			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall("15", thirdTradingId.toString(),
					totalPrice.subtract(useAccountAmount).toString(),
					userId.intValue());

			Thread.sleep(4000);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			Thread.sleep(2000);

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Map m = new HashMap();

			m.put("userId", userId);
			m.put("bizno", orderId);
			m.put("originalNo", orderId);

			// 订单表(order)
			OrderPo orderPo = database.selectOrderbyOrderId(orderId);

			AccountEntry res = new AccountWapper().selectAccountEntryByBizNo(m)
					.get(0);

			DataUtil.verifyDecimalEquals(orderPo.getAccountPaidAmount(),
					res.getAmount(), "校验取消订单退款入账流水金额");

			// 用户退款资金详情表（user_refund_fund_detail）
			UserRefundFundDetailPo userRefundFundDetailPo = database
					.selectUserRefundFundDetailByPaymentId(Long
							.valueOf(thirdTradingId));

			UserRefundFundDetailPo expectUserRefundFundDetailPo = new UserRefundFundDetailPo();

			expectUserRefundFundDetailPo.setPaymentId(Long
					.valueOf(thirdTradingId));
			expectUserRefundFundDetailPo.setAccountRefundStatus(4);
			expectUserRefundFundDetailPo.setBizType(2);
			expectUserRefundFundDetailPo.setThirdpartyAmount(orderPo
					.getThirdpartyPaidAmount());
			expectUserRefundFundDetailPo.setThirdpartyRefundStatus(3);
			expectUserRefundFundDetailPo.setRetryTimes(0);
			expectUserRefundFundDetailPo.setMemo("0");
			expectUserRefundFundDetailPo.setAccountAmount(orderPo
					.getAccountPaidAmount());

			verifyUserRefundFundDetailDb(expectUserRefundFundDetailPo,
					userRefundFundDetailPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	// 已经没有招行折扣了
	public void Tc_CancelOrder_026() {
		Logger.start(true, "订单用招行全款支付,卖家接单前取消订单,校验原路退回");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = placeOrder5(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			BigDecimal useAccountAmount = BigDecimal.ZERO;

			Long thirdTradingId = TradingCallService.payOrder(userId,
					useAccountAmount, placeOrderResp.getMainOrderId(), "50");

			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall("50", thirdTradingId.toString(),
					totalPrice.subtract(useAccountAmount).toString(),
					userId.intValue());

			Thread.sleep(4000);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			Thread.sleep(2000);

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			// 订单表(order)
			OrderPo orderPo = database.selectOrderbyOrderId(orderId);

			// 用户退款资金详情表（user_refund_fund_detail）
			UserRefundFundDetailPo userRefundFundDetailPo = database
					.selectUserRefundFundDetailByPaymentId(Long
							.valueOf(thirdTradingId));

			UserRefundFundDetailPo expectUserRefundFundDetailPo = new UserRefundFundDetailPo();

			expectUserRefundFundDetailPo.setPaymentId(Long
					.valueOf(thirdTradingId));
			expectUserRefundFundDetailPo.setAccountRefundStatus(-1);
			expectUserRefundFundDetailPo.setBizType(2);
			expectUserRefundFundDetailPo.setThirdpartyAmount(orderPo
					.getThirdpartyPaidAmount());
			expectUserRefundFundDetailPo.setThirdpartyRefundStatus(3);
			expectUserRefundFundDetailPo.setRetryTimes(0);
			expectUserRefundFundDetailPo.setMemo("0");
			expectUserRefundFundDetailPo.setAccountAmount(orderPo
					.getAccountPaidAmount());

			verifyUserRefundFundDetailDb(expectUserRefundFundDetailPo,
					userRefundFundDetailPo);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_CancelOrder_027() {
		Logger.start(true, "一笔交易生成多个订单,(用户余额+招行支付),取消其中一单。校验退款余额和第三方支付的原路返回");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = placeOrder5(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			BigDecimal useAccountAmount = new BigDecimal(10);

			Long thirdTradingId = TradingCallService.payOrder(userId,
					useAccountAmount, placeOrderResp.getMainOrderId(), "50");

			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall("50", thirdTradingId.toString(),
					totalPrice.subtract(useAccountAmount).toString(),
					userId.intValue());

			Thread.sleep(4000);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			Thread.sleep(2000);

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			Map m = new HashMap();

			m.put("userId", userId);
			m.put("bizno", orderId);
			m.put("originalNo", orderId);

			// 订单表(order)
			OrderPo orderPo = database.selectOrderbyOrderId(orderId);

			AccountEntry res = new AccountWapper().selectAccountEntryByBizNo(m)
					.get(0);

			DataUtil.verifyDecimalEquals(orderPo.getAccountPaidAmount(),
					res.getAmount(), "校验取消订单退款入账流水金额");

			// 用户退款资金详情表（user_refund_fund_detail）
			UserRefundFundDetailPo userRefundFundDetailPo = database
					.selectUserRefundFundDetailByPaymentId(Long
							.valueOf(thirdTradingId));

			UserRefundFundDetailPo expectUserRefundFundDetailPo = new UserRefundFundDetailPo();

			expectUserRefundFundDetailPo.setPaymentId(Long
					.valueOf(thirdTradingId));
			expectUserRefundFundDetailPo.setAccountRefundStatus(4);
			expectUserRefundFundDetailPo.setBizType(2);
			expectUserRefundFundDetailPo.setThirdpartyAmount(orderPo
					.getThirdpartyPaidAmount());
			expectUserRefundFundDetailPo.setThirdpartyRefundStatus(3);
			expectUserRefundFundDetailPo.setRetryTimes(0);
			expectUserRefundFundDetailPo.setMemo("0");
			expectUserRefundFundDetailPo.setAccountAmount(orderPo
					.getAccountPaidAmount());

			verifyUserRefundFundDetailDb(expectUserRefundFundDetailPo,
					userRefundFundDetailPo);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	// 宝付渠道已经去除
	public void Tc_CancelOrder_028() {
		Logger.start(true, "订单用宝付全款支付,卖家接单前取消订单,校验原路退回到支付宝");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = placeOrder5(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			BigDecimal useAccountAmount = BigDecimal.ZERO;

			Long thirdTradingId = TradingCallService.payOrder(userId,
					useAccountAmount, placeOrderResp.getMainOrderId(), "13");

			// 支付网关支付回调交易
			PayGateWayCallService.notifyCall("13", thirdTradingId.toString(),
					totalPrice.subtract(useAccountAmount).toString(),
					userId.intValue());

			Thread.sleep(4000);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			Thread.sleep(2000);

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());
			
			// 订单表(order)
			OrderPo orderPo = database.selectOrderbyOrderId(orderId);

			// 用户退款资金详情表（user_refund_fund_detail）
			UserRefundFundDetailPo userRefundFundDetailPo = database
					.selectUserRefundFundDetailByPaymentId(Long
							.valueOf(thirdTradingId));

			UserRefundFundDetailPo expectUserRefundFundDetailPo = new UserRefundFundDetailPo();

			expectUserRefundFundDetailPo.setPaymentId(Long
					.valueOf(thirdTradingId));
			expectUserRefundFundDetailPo.setAccountRefundStatus(-1);
			expectUserRefundFundDetailPo.setBizType(2);
			expectUserRefundFundDetailPo.setThirdpartyAmount(orderPo
					.getThirdpartyPaidAmount());
			expectUserRefundFundDetailPo.setThirdpartyRefundStatus(3);
			expectUserRefundFundDetailPo.setRetryTimes(0);
			expectUserRefundFundDetailPo.setMemo("0");
			expectUserRefundFundDetailPo.setAccountAmount(orderPo
					.getAccountPaidAmount());

			verifyUserRefundFundDetailDb(expectUserRefundFundDetailPo,
					userRefundFundDetailPo);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_029() {
		Logger.start(true, "预售商品订单，买手接单后,买手取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = createPreSaleOrder();
			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			long sellerId = order.getSellerId();

			// 付款
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证

			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_030() {
		Logger.start(true, "预售商品订单，买手接单后,用户取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = createPreSaleOrder();
			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			long sellerId = order.getSellerId();

			// 付款
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("102", cancelordercall.getBCode(), "验证bcode");
			Logger.verifyEquals(String.format("买家取消订单%s状态不匹配", orderId),
					cancelordercall.getMsg(), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_031() {
		Logger.start(true, "预售商品订单，买手接单后,客服取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = createPreSaleOrder();
			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			long sellerId = order.getSellerId();

			// 付款
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_032() {
		Logger.start(true, "预售商品订单,付款后，超过120小时未接单，用户取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = createPreSaleOrder();

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 付款
			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");

			OrderPo record = database.selectOrderbyOrderId(orderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR_OF_DAY, -121);
			;

			record.setAddTime(calendar.getTime());
			record.setPaidTime(calendar.getTime());

			// 修改订单表 下单时间 为120小时前
			database.orderMapper.updateByPrimaryKey(record);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	// 手工校验发送返库存消息 send trading_addproductstock message
	public void Tc_CancelOrder_033() {
		Logger.start(true, "砍价团订单支付成功后,砍价团服务通知交易组团成功后,取消订单失败");
		try {
			Logger.comment("准备前置数据");

			String bizId = TestDataManager.getRandomNum(9);

			TradingServiceResp placeOrderResp = BargainGroupService
					.openGroup(bizId);
			// 砍价团id
			long userId = placeOrderResp.getUserId();
			long orderId1 = placeOrderResp.getOrderList().get(0).getOrderId();

			// 砍价团参团订单
			BargainGroupService.joinGroup(bizId);

			BargainGroupService.notifyOrderBizStatus(bizId, orderId1, 1, 3);

			Logger.comment("准备前置数据结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId1);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("103", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(
					String.format("哈尼，已成团的订单不能取消，如有商品质量问题，可在收到货物后，申请退货退款"),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_034() {
		Logger.start(true, "砍价团订单下单未支付后,允许取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithBargainGroup(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			verifyOrderStatus(12, order.getOrderId(),
					cancelorderReq.getUserId(), cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_035() {
		Logger.start(true, "砍价团订单支付成功后,砍价团服务通知交易消息之前,不允许取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithBargainGroup(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId,
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getMainOrderId(), "13");

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("103", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(String.format("此订单%s组团成功前不能被取消", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_036() {
		Logger.start(true, "砍价团订单支付成功后,砍价团服务通知交易开团成功,取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			String bizId = TestDataManager.getRandomNum(9);
			TradingServiceResp placeOrderResp = BargainGroupService
					.openGroup(bizId);
			// 砍价团id
			long userId = placeOrderResp.getUserId();
			long orderId1 = placeOrderResp.getOrderList().get(0).getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId1, 1, 1);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId1);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("103", cancelordercall.getBCode(), "验证Code");

			Logger.verifyEquals(String.format("此订单%s组团成功前不能被取消", orderId1),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_037() {
		Logger.start(true, "砍价团订单支付成功后,砍价团服务通知交易参团成功,取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			String bizId = TestDataManager.getRandomNum(9);
			TradingServiceResp placeOrderResp = BargainGroupService
					.openGroup(bizId);
			// 砍价团id
			long userId = placeOrderResp.getUserId();
			long orderId1 = placeOrderResp.getOrderList().get(0).getOrderId();

			TradingServiceResp placeOrderResp2 = BargainGroupService
					.joinGroup(bizId);

			long orderId2 = placeOrderResp2.getOrderList().get(0).getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId2, 2, 2);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId1);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("103", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(String.format("此订单%s组团成功前不能被取消", orderId1),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_038() {
		Logger.start(true, "取消订单，交易发送返回库存消息");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLuxury(false);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证

			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_039() {
		Logger.start(true, "订单一个商品,退款拒绝后,客服取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 拒绝退款
			RefundService.rejectRefundBill(order);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(false, cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_040() {
		Logger.start(true, "多商品订单,其中一个商品部分退货成功后,客服取消订单");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = placeOrder5(true);

			Order order = placeOrderResp.getOrderList().get(1);

			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			TradingCallService.payOrder(userId, amount, tradingId);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 退款
			ApplyRefundReq applyRefundReq = RefundService
					.buildStandApplyRefundReq(order);

			applyRefundReq.getSalesRefundInfoList().get(1)
					.setRefundAmount(BigDecimal.TEN);
			applyRefundReq.getSalesRefundInfoList().remove(0);

			RefundService.applyRefundCall(applyRefundReq);

			RefundService.approveRefundBillCall(applyRefundReq);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(false, cancelorderReq);
			cancelordercall.callService();

			// 查询交易，退款同步表

			// 资金流水表

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_041() {
		Logger.start(true, "多商品订单,部分商品退货的数量大于实际购买数量,客服取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = placeOrder5(true);

			Order order = placeOrderResp.getOrderList().get(1);

			long orderId = order.getOrderId();
			long sellerId = order.getSellerId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			TradingCallService.payOrder(userId, amount, tradingId);

			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 退款
			ApplyRefundReq applyRefundReq = RefundService
					.buildStandApplyRefundReq(order);

			applyRefundReq.getSalesRefundInfoList().get(1)
					.setRefundProductNum(10);

			applyRefundReq.getSalesRefundInfoList().remove(0);

			RefundService.applyRefundCall(applyRefundReq);

			RefundService.approveRefundBillCall(applyRefundReq);

			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(false, cancelorderReq);
			cancelordercall.callService();

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_042() {
		Logger.start(false, "订单支付前,重复取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLuxury(false);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			// 保留两位小数

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			// cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("107", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(String.format("此订单%s已取消~", orderId),
					cancelordercall.getMsg(), "验证Msg");

			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_043() {
		Logger.start(false, "订单不存在");
		try {
			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			long orderId = 11;
			cancelorderReq.setOrderId(orderId);
			long userId = 1113;
			cancelorderReq.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("101", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyIsContains(String.format("订单号不存在:%s", orderId),
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_044() {
		Logger.start(false, "买家用户不是订单的所有者");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLuxury(false);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();

			String cancelReason = "自动化测试取消订单";
			Logger.comment("前置数据准备结束");
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId + 1);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("用户" + cancelorderReq.getUserId() + "不是订单"
					+ orderId + "的所有者", cancelordercall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_046() {
		Logger.start(true, "使用了预付卡订单,付款前取消订单");
		try {
			Logger.comment("准备前置数据");

			TradingServiceResp placeOrderResp = PrepaidCardService
					.placeOrder2(false);

			List<Order> orders = placeOrderResp.getOrderList();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			long userId = placeOrderResp.getUserId();

			long orderId = orders.get(0).getOrderId();

			Logger.comment("准备前置数据结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(sellerId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			
			Thread.sleep(2000);

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason()); // 数据库验证
			
			database.clearCache();

			// 订单表(order)
			OrderPo ymtOrders = database.selectOrderbyOrderId(orderId);

			DataUtil.verifyDecimalEquals(
					ymtOrders.getCardAmount(),
					PrepaidCardService.getCardEntry((int) userId,
							String.valueOf(orderId)), "校验取消订单退回的预付卡金额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_048() {
		Logger.start(true, "使用app内立减支付,付款前取消订单");
		try {
			Logger.comment("准备前置数据");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false, BigDecimal.TEN,
							userId, LogisticsTypeEnum.OVERSEAS_DELIVERY);

			List<Order> orders = placeOrderResp.getOrderList();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			long orderId = orders.get(0).getOrderId();
			Logger.comment("准备前置数据结束");

			MainOrderPo beforeCancel_actualMainOrder = database
					.selectMianOrderbyId(placeOrderResp.getMainOrderId());
			BigDecimal beforeCancel_payDeductAmount = beforeCancel_actualMainOrder
					.getPayDeductAmount();

			// 取消订单前验证payDeductAmount是否有值
			Logger.verifyEquals(true, Utils.isBiggerThan(
					beforeCancel_payDeductAmount, BigDecimal.ZERO),
					"取消订单前验证payDeductAmount是否有值");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(sellerId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证

			Thread.sleep(2000);

			// 数据库验证
			verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason()); // 数据库验证

			MainOrderPo afterCancel_actualMainOrder = database
					.selectMianOrderbyId(placeOrderResp.getMainOrderId());
			BigDecimal afterCancel_payDeductAmount = afterCancel_actualMainOrder
					.getPayDeductAmount();
			// 取消订单后验证payDeductAmount是否有值
			Logger.verifyEquals(false, Utils.isBiggerThan(
					afterCancel_payDeductAmount, BigDecimal.ZERO),
					"取消订单后payDeductAmount是否有值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_049() {
		Logger.start(true, "含app内立减支付订单已支付商家未接单,买家取消订单成功，订单状态为12 买家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false, BigDecimal.TEN,
							userId, LogisticsTypeEnum.OVERSEAS_DELIVERY);
			List<Order> orders = placeOrderResp.getOrderList();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			long orderId = orders.get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			MainOrderPo beforeCancel_actualMainOrder = database
					.selectMianOrderbyId(placeOrderResp.getMainOrderId());
			BigDecimal beforeCancel_payDeductAmount = beforeCancel_actualMainOrder
					.getPayDeductAmount();

			BigDecimal totalPrice = TradingCallService.getPayableAmount(
					placeOrderResp.getMainOrderId()).subtract(
					beforeCancel_payDeductAmount);

			TradingCallService.payOrder(placeOrderResp.getUserId(), totalPrice,
					placeOrderResp.getMainOrderId(), true, 2);

			// 取消订单前验证payDeductAmount是否有值
			Logger.verifyEquals(true, Utils.isBiggerThan(
					beforeCancel_payDeductAmount, BigDecimal.ZERO),
					"取消订单前验证payDeductAmount是否有值");

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(sellerId);
			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

			MainOrderPo afterCancel_actualMainOrder = database
					.selectMianOrderbyId(placeOrderResp.getMainOrderId());
			BigDecimal afterCancel_payDeductAmount = afterCancel_actualMainOrder
					.getPayDeductAmount();
			// 取消订单后验证payDeductAmount是否有值
			Logger.verifyEquals(true, Utils.isBiggerThan(
					afterCancel_payDeductAmount, BigDecimal.ZERO),
					"取消订单前验证payDeductAmount是否有值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_054() {
		Logger.start(true, "定金订单未支付定金,系统取消订单,订单状态为18");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SYSTEM_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			OrderPo record = database.selectOrderbyOrderId(orderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, -10);

			record.setAddTime(calendar.getTime());

			record.setAutoCancelHour(new BigDecimal("0.00"));

			// 修改订单表，下单时间，自动确认收货时间
			database.orderMapper.updateByPrimaryKey(record);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_055() {
		Logger.start(true, "定金订单已经支付定金,买家取消订单,取消失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long tradingId = placeOrderResp.getTradingId();
			long userId = placeOrderResp.getUserId();
			BigDecimal earnestAmount = placeOrderResp.getPayableAmount();

			TradingCallService.payEngageOrder(userId, earnestAmount, tradingId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals("哈尼，已支付定金预售订单不能取消~", cancelordercall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_056() {
		Logger.start(true, "定金订单未支付定金,系统自动取消订单,订单状态为18");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			// 修改下单时间
			OrderPo record = database.selectOrderbyOrderId(orderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR, -1);

			record.setAddTime(calendar.getTime());

			database.orderMapper.updateByPrimaryKey(record);

			String orderJson = "{\"cancelReason\":\"自动化测试取消订单\",\"cancelType\":\"4\",\"orderId\":"
					+ orderId + ",\"userId\":" + userId + "}";

			// 发送请求
			YmatouEasyCall autoCancelOrderCall = new YmatouEasyCall("", "POST",
					"JSON");
			autoCancelOrderCall
					.setUrl("http://optrade.iapi.ymatou.com/api/Buyer/AutoCancelOrder");
			autoCancelOrderCall.setData(orderJson);
			autoCancelOrderCall.callService();

			Logger.verifyEquals("ok", autoCancelOrderCall.getReturnData(),
					"验证ReturnData");

			// 数据库验证
			OrderPo actualOrder = database
					.selectOrderbyOrderId(orderId);

			Logger.verifyEquals(18, actualOrder.getOrderStatus(),
					"验证orderStatus");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_057() {
		Logger.start(true, "定金订单已经支付定金, 卖家取消订单,取消失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long tradingId = placeOrderResp.getTradingId();
			long userId = placeOrderResp.getUserId();
			BigDecimal earnestAmount = placeOrderResp.getPayableAmount();

			TradingCallService.payEngageOrder(userId, earnestAmount, tradingId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals("哈尼，已支付定金预售订单不能取消~", cancelordercall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_058() {
		Logger.start(true, "定金订单已经支付定金, 系统取消订单,取消成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			TradingServiceResp placeOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();
			long tradingId = placeOrderResp.getTradingId();
			long userId = placeOrderResp.getUserId();
			BigDecimal earnestAmount = placeOrderResp.getPayableAmount();

			TradingCallService.payEngageOrder(userId, earnestAmount, tradingId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SYSTEM_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_060() {
		Logger.start(true, "定金订单二次确认, 卖家取消订单,取消失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 二次确认下单
			TradingPlaceEngageOrderCallService.placeFullPaidOrder(userId, engageOrderId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(engageOrderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals("哈尼，已支付定金预售订单不能取消~", cancelordercall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_061() {
		Logger.start(true, "定金订单二次确认, 买家取消订单,取消失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 二次确认下单
			TradingPlaceEngageOrderCallService.placeFullPaidOrder(userId, engageOrderId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(engageOrderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals("哈尼，已支付定金预售订单不能取消~", cancelordercall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_062() {
		Logger.start(true, "定金订单二次确认, 系统取消订单,取消成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 二次确认下单
			TradingPlaceEngageOrderCallService.placeFullPaidOrder(userId, engageOrderId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SYSTEM_CANCEL_ORDER);
			cancelorderReq.setOrderId(engageOrderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, engageOrderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_065() {
		Logger.start(true, "定金订单全款支付后, 系统取消订单, 取消成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 二次确认下单并支付
			TradingCallService.payFullPaidOrder(userId, engageOrderId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SYSTEM_CANCEL_ORDER);
			cancelorderReq.setOrderId(engageOrderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, engageOrderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_066() {
		Logger.start(true, "定金订单全款支付后, 卖家取消订单,取消失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 二次确认下单并支付
			TradingCallService.payFullPaidOrder(userId, engageOrderId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
			cancelorderReq.setOrderId(engageOrderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals("哈尼，已支付定金预售订单不能取消~", cancelordercall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_067() {
		Logger.start(true, "定金订单全款支付后, 买家取消订单,取消失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 二次确认下单并支付
			TradingCallService.payFullPaidOrder(userId, engageOrderId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(engageOrderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals("哈尼，已支付定金预售订单不能取消~", cancelordercall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_071() {
		Logger.start(true, "定金订单全款支付超时, 系统自动取消成功, 回退到订单待二次确认状态");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 二次确认下单
			TradingPlaceEngageOrderCallService.placeFullPaidOrder(userId, engageOrderId);

			// 修改二次确认时间
			OrderPo record = database
					.selectOrderbyOrderId(engageOrderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, -10);

			record.setSecondConfirmTime(calendar.getTime());

			// 修改二次确认时间
			database.orderMapper.updateByPrimaryKey(record);

			String orderJson = "{\"cancelReason\":\"自动化测试取消订单\",\"cancelType\":\"10\",\"orderId\":"
					+ engageOrderId + ",\"userId\":" + userId + "}";
			// 发送请求
			YmatouEasyCall autoCancelOrderCall = new YmatouEasyCall("", "POST",
					"JSON");
			autoCancelOrderCall
					.setUrl("http://optrade.iapi.ymatou.com/api/Buyer/bookingOrderUnPaidFullAmountAutoCancel");
			autoCancelOrderCall.setData(orderJson);
			autoCancelOrderCall.callService();

			Logger.verifyEquals("ok", autoCancelOrderCall.getReturnData(),
					"验证ReturnData");

			// 数据库验证
			OrderPo actualOrder = database
					.selectOrderbyOrderId(engageOrderId);

			Logger.verifyEquals(true, actualOrder.getCanConfirm(),
					"验证canconfirm");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_072() {
		Logger.start(true, "定金订单已经支付全款, 系统自动取消失败，订单依然是已付款状态");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 二次确认下单并支付
			TradingCallService.payFullPaidOrder(userId, engageOrderId);

			String orderJson = "{\"cancelReason\":\"自动化测试取消订单\",\"cancelType\":\"4\",\"orderId\":"
					+ engageOrderId + ",\"userId\":" + userId + "}";
			// 发送请求
			YmatouEasyCall autoCancelOrderCall = new YmatouEasyCall("", "POST",
					"JSON");
			autoCancelOrderCall
					.setUrl("http://optrade.iapi.ymatou.com/api/Buyer/AutoCancelOrder");
			autoCancelOrderCall.setData(orderJson);
			autoCancelOrderCall.callService();

			Logger.verifyEquals("ok", autoCancelOrderCall.getReturnData(),
					"验证ReturnData");

			// 数据库验证
			OrderPo actualOrder = database
					.selectOrderbyOrderId(engageOrderId);

			Logger.verifyEquals(2, actualOrder.getOrderStatus(),
					"验证orderStatus");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_073() {
		Logger.start(true, "定金订单已经支付定金, 系统自动取消失败，订单依然是待支付全款状态");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 修改下单时间
			OrderPo record = database
					.selectOrderbyOrderId(engageOrderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR, -1);

			record.setAddTime(calendar.getTime());

			database.orderMapper.updateByPrimaryKey(record);

			String orderJson = "{\"cancelReason\":\"自动化测试取消订单\",\"cancelType\":\"4\",\"orderId\":"
					+ engageOrderId + ",\"userId\":" + userId + "}";
			// 发送请求
			YmatouEasyCall autoCancelOrderCall = new YmatouEasyCall("", "POST",
					"JSON");
			autoCancelOrderCall
					.setUrl("http://optrade.iapi.ymatou.com/api/Buyer/AutoCancelOrder");
			autoCancelOrderCall.setData(orderJson);
			autoCancelOrderCall.callService();

			Logger.verifyEquals("ok", autoCancelOrderCall.getReturnData(),
					"验证ReturnData");

			// 数据库验证
			OrderPo actualOrder = database
					.selectOrderbyOrderId(engageOrderId);

			Logger.verifyEquals(1, actualOrder.getOrderStatus(),
					"验证orderStatus");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_081() {
		Logger.start(true, "定金订单全款支付超过paymentEndTime（新接口），买家违约，系统自动取消成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 二次确认下单
			TradingPlaceEngageOrderCallService.placeFullPaidOrder(userId, engageOrderId);

			// 修改paymentEndTime
			OrderPo record = database
					.selectOrderbyOrderId(engageOrderId);

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, -10);

			record.setPaymentEndTime(calendar.getTime());

			// 修改paymentEndTime
			database.orderMapper.updateByPrimaryKey(record);

			String orderJson = "{\"cancelReason\":\"自动化测试取消订单\",\"cancelType\":\"8\",\"orderId\":"
					+ engageOrderId + ",\"userId\":" + userId + "}";
			// 发送请求
			YmatouEasyCall autoCancelOrderCall = new YmatouEasyCall("", "POST",
					"JSON");
			autoCancelOrderCall
					.setUrl("http://optrade.iapi.ymatou.com/api/Buyer/bookingOrderUserViolationAutoCancel");
			autoCancelOrderCall.setData(orderJson);
			autoCancelOrderCall.callService();

			Logger.verifyEquals("ok", autoCancelOrderCall.getReturnData(),
					"验证ReturnData");

			// 数据库验证
			OrderPo actualOrder = database
					.selectOrderbyOrderId(engageOrderId);

			Logger.verifyEquals(18, actualOrder.getOrderStatus(),
					"验证orderStatus");
			Logger.verifyEquals("买家超时未付全款，系统自动取消",
					actualOrder.getCancelReason(), "验证orderStatus");
			Logger.verifyEquals(400000, actualOrder.getOrderStatusMemo(),
					"验证orderStatusMemo");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_084() {
		Logger.start(true, "使用了返点金额的订单支付前,买家取消订单成功,订单状态为12 买家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			// 下单前返点账户余额
			BigDecimal beforeAmount = AccountCallServiceV2.getAccountBalance(
					20238699, 5);
			
			TradingServiceResp placeOrderResp = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();

			String cancelReason = "自动化测试取消订单";

			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());
			
			// 取消订单后的返点账户余额
			BigDecimal afterAmount = AccountCallServiceV2.getAccountBalance(
					20238699, 5);
			
			DataUtil.verifyDecimalEquals(BigDecimal.ZERO,
					afterAmount.subtract(beforeAmount), "验证用户返点账户余额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_085() {
		Logger.start(true, "使用了返点金额的订单支付前, 系统自动取消订单,订单状态为18 系统取消");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			
			// 下单前返点账户余额
			BigDecimal beforeAmount = AccountCallServiceV2.getAccountBalance(
					20238699, 5);
			
			TradingServiceResp placeOrderResp = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false);

			OrderPo order = placeOrderResp.getOrderList().get(0).getOrderPo();

			long orderId = order.getOrderId();

			long userId = placeOrderResp.getUserId();
			
			TradingSyncService.getSyncResult(orderId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.SYSTEM_CANCEL_ORDER);
			cancelorderReq.setOrderId(orderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());
			
			// 取消订单后的返点账户余额
			BigDecimal afterAmount = AccountCallServiceV2.getAccountBalance(
					20238699, 5);

			DataUtil.verifyDecimalEquals(BigDecimal.ZERO,
					afterAmount.subtract(beforeAmount), "验证用户返点账户余额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_086() {
		Logger.start(true, "使用了返点金额的订单已支付商家未接单,买家取消订单成功，订单状态为12 买家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			// 下单前返点账户余额
			BigDecimal beforeAmount = AccountCallServiceV2.getAccountBalance(
					20238699, 5);

			TradingServiceResp placeOrderResp = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, 0);
			
			// 支付订单
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());

			for (Order order : placeOrderResp.getOrderList()) {

				long orderId = order.getOrderId();

				long userId = placeOrderResp.getUserId();

				Logger.comment("前置数据准备结束");
				String cancelReason = "自动化测试取消订单";
				cancelorderReq.setCancelReason(cancelReason);
				cancelorderReq
						.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
				cancelorderReq.setOrderId(orderId);
				cancelorderReq.setUserId(userId);
				// 发送请求
				cancelordercall.setData(cancelorderReq);
				cancelordercall.callService();
				Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
						"验证Code");
				// 数据库验证
				verifyOrderStatus(12, orderId, cancelorderReq.getUserId(),
						cancelorderReq.getCancelType(),
						cancelorderReq.getCancelReason());
			}
			
			Thread.sleep(5000);
			
			// 取消订单后的返点账户余额
			BigDecimal afterAmount = AccountCallServiceV2.getAccountBalance(
					20238699, 5);

			DataUtil.verifyDecimalEquals(BigDecimal.ZERO,
					afterAmount.subtract(beforeAmount), "验证用户返点账户余额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_087() {
		Logger.start(true, "使用了返点金额的订单已支付商家未接单,卖家取消订单成功，订单状态为13 卖家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			// 下单前返点账户余额
			BigDecimal beforeAmount = AccountCallServiceV2.getAccountBalance(
					20238699, 5);

			TradingServiceResp placeOrderResp = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, 0);
			
			// 支付订单
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());

			for (Order order : placeOrderResp.getOrderList()) {

				long orderId = order.getOrderId();

				long sellerId = order.getSellerId();

				Logger.comment("前置数据准备结束");
				String cancelReason = "自动化测试取消订单";
				cancelorderReq.setCancelReason(cancelReason);
				cancelorderReq
						.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
				cancelorderReq.setOrderId(orderId);
				cancelorderReq.setUserId(sellerId);
				// 发送请求
				cancelordercall.setData(cancelorderReq);
				cancelordercall.callService();
				Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
						"验证Code");
				// 数据库验证
				verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
						cancelorderReq.getCancelType(),
						cancelorderReq.getCancelReason());

			}
			
			Thread.sleep(5000);
			
			BigDecimal afterAmount = AccountCallServiceV2.getAccountBalance(
					20238699, 5);

			DataUtil.verifyDecimalEquals(BigDecimal.ZERO,
					afterAmount.subtract(beforeAmount), "验证用户返点账户余额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_088() {
		Logger.start(true, "体验会员订单支付后卖家取消订单成功，订单状态为13 卖家取消订单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, 1);
			
			// 支付订单
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());

			for (Order order : placeOrderResp.getOrderList()) {

				long orderId = order.getOrderId();

				long sellerId = order.getSellerId();

				Logger.comment("前置数据准备结束");
				String cancelReason = "自动化测试取消订单";
				cancelorderReq.setCancelReason(cancelReason);
				cancelorderReq
						.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
				cancelorderReq.setOrderId(orderId);
				cancelorderReq.setUserId(sellerId);
				// 发送请求
				cancelordercall.setData(cancelorderReq);
				cancelordercall.callService();
				Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
						"验证Code");
				// 数据库验证
				verifyOrderStatus(13, orderId, cancelorderReq.getUserId(),
						cancelorderReq.getCancelType(),
						cancelorderReq.getCancelReason());

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_089() {
		Logger.start(true, "安利会员订单支付后卖家取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, 2);
			
			// 支付订单
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());

			for (Order order : placeOrderResp.getOrderList()) {

				long orderId = order.getOrderId();

				long sellerId = order.getSellerId();

				Logger.comment("前置数据准备结束");
				String cancelReason = "自动化测试取消订单";
				cancelorderReq.setCancelReason(cancelReason);
				cancelorderReq
						.setCancelType(CancelOrderTypeEnum.SELLER_CANCEL_ORDER);
				cancelorderReq.setOrderId(orderId);
				cancelorderReq.setUserId(sellerId);
				// 发送请求
				cancelordercall.setData(cancelorderReq);
				cancelordercall.callService();
				
				Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
						"验证Code");

				Logger.verifyEquals("103", cancelordercall.getBCode(), "验证bcode");

				Logger.verifyEquals(String.format("已购买的会员订单%s，只有客服能取消", orderId),
						cancelordercall.getMsg(), "验证Msg");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_090() {
		Logger.start(true, "海淘会员订单支付后买家取消订单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, 3);
			
			// 支付订单
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());

			for (Order order : placeOrderResp.getOrderList()) {

				long orderId = order.getOrderId();

				long sellerId = order.getSellerId();

				Logger.comment("前置数据准备结束");
				String cancelReason = "自动化测试取消订单";
				cancelorderReq.setCancelReason(cancelReason);
				cancelorderReq
						.setCancelType(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);
				cancelorderReq.setOrderId(orderId);
				cancelorderReq.setUserId(sellerId);
				// 发送请求
				cancelordercall.setData(cancelorderReq);
				cancelordercall.callService();
				
				Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
						"验证Code");

				Logger.verifyEquals("103", cancelordercall.getBCode(), "验证bcode");

				Logger.verifyEquals(String.format("已购买的会员订单%s，只有客服能取消", orderId),
						cancelordercall.getMsg(), "验证Msg");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_091() {
		Logger.start(true, "海淘会员订单支付后客服取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceAnliOrderCallService
					.placeAnlihuiOrder(BigDecimal.TEN, false, 3);
			
			// 支付订单
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());

			for (Order order : placeOrderResp.getOrderList()) {

				long orderId = order.getOrderId();

				long sellerId = order.getSellerId();

				Logger.comment("前置数据准备结束");
				String cancelReason = "自动化测试取消订单";
				cancelorderReq.setCancelReason(cancelReason);
				cancelorderReq
						.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
				cancelorderReq.setOrderId(orderId);
				cancelorderReq.setUserId(sellerId);
				// 发送请求
				cancelordercall.setData(cancelorderReq);
				cancelordercall.callService();
				
				Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
						"验证Code");
				// 数据库验证
				verifyOrderStatus(18, orderId, cancelorderReq.getUserId(),
						cancelorderReq.getCancelType(),
						cancelorderReq.getCancelReason());
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_108() {
		Logger.start(true, "定金订单全款支付后, 客服取消订单, 取消成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			// 二次确认下单并支付
			TradingCallService.payFullPaidOrder(userId, engageOrderId);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(engageOrderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyOrderStatus(18, engageOrderId, cancelorderReq.getUserId(),
					cancelorderReq.getCancelType(),
					cancelorderReq.getCancelReason());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_109() {
		Logger.start(true, "定金订单定金支付后, 客服取消订单, 取消成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp engagePlaceOrderResp = TradingPlaceEngageOrderCallService
					.placeEngageOrder(false);
			Long userId = engagePlaceOrderResp.getUserId();
			long tradingId = engagePlaceOrderResp.getTradingId();
			long engageOrderId = engagePlaceOrderResp.getOrderList().get(0)
					.getOrderId();

			// 支付定金
			TradingCallService.payOrder(userId,
					engagePlaceOrderResp.getPayableAmount(), tradingId, 2);

			String cancelReason = "自动化测试取消订单";
			cancelorderReq.setCancelReason(cancelReason);
			cancelorderReq
					.setCancelType(CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER);
			cancelorderReq.setOrderId(engageOrderId);
			cancelorderReq.setUserId(userId);

			// 发送请求
			cancelordercall.setData(cancelorderReq);
			cancelordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");

			Logger.verifyEquals("105", cancelordercall.getBCode(), "验证bcode");

			Logger.verifyEquals(String.format("客服不能取消已支付定金预售订单,%s", engageOrderId), cancelordercall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
